package com.hb.trade.server.project.deal.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hb.core.pojo.parent.MPCommonEntity;
import com.hb.core.pojo.parent.PageResult;
import com.hb.core.pojo.project.deal.dto.BidCandidateSupplierDTO;
import com.hb.core.pojo.project.deal.entity.BidCandidateSupplier;
import com.hb.core.pojo.project.deal.mapper.BidCandidateSupplierMapper;
import com.hb.trade.server.project.deal.service.BidCandidateSupplierService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 中标候选人公示供应商对应Service实现类
 *
 * @author Lix1ang
 * @date 2021-12-24 14:08:17
 */
@Service
public class BidCandidateSupplierServiceImpl extends ServiceImpl<BidCandidateSupplierMapper, BidCandidateSupplier> implements BidCandidateSupplierService {


    /**
     *
     * @Description: 查询标段的中标候选人公示最后一次中标人候选人列表
     * @Author: zhongdl
     * @Date:2022/1/6 9:04
     * @param pages:
     * @param sectionId: 标段id
     * @param candidateId: 中标候选人id
     * @param orgName:企业名称
     * @return: {@link PageResult< BidCandidateSupplierDTO> }
     **/
    @Override
    public PageResult<BidCandidateSupplierDTO> pageCandidate(Page pages, Long sectionId, Long candidateId, String orgName) {
        baseMapper.pageCandidate(pages,sectionId,candidateId,orgName);
        return PageResult.get(pages);
    }

    @Override
    public List<BidCandidateSupplierDTO> listBidCandidateSupplierDTO(Long sectionId, Long candidateId) {
        QueryWrapper<BidCandidateSupplier> wrapper = BidCandidateSupplier.wrapper();
        wrapper.eq("section_id",sectionId).eq("candidate_id",candidateId);
        List<BidCandidateSupplierDTO> listBidCandidateSupplierDTO = CollUtil.list(false);
        List<BidCandidateSupplier> list = list(wrapper);

        if (CollUtil.isEmpty(list)){
            return listBidCandidateSupplierDTO;
        }
        for (BidCandidateSupplier bidCandidateSupplier : list) {
            listBidCandidateSupplierDTO.add(bidCandidateSupplier.to(BidCandidateSupplierDTO.class));
        }
        return listBidCandidateSupplierDTO;
    }
}
